Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use the created logger and not the root logger #34

Merged
merged 1 commit into from
May 14, 2024
Merged

Conversation

madeddie
Copy link
Owner

@madeddie madeddie commented May 14, 2024

Summary by CodeRabbit

  • Chores

    • Updated .gitignore to ignore .envrc files.
  • Refactor

    • Improved logging during the login process and cookie file reading for better error handling.

Copy link
Contributor

coderabbitai bot commented May 14, 2024

Walkthrough

The recent changes include updating the .gitignore file to exclude .envrc files, ensuring sensitive environment configurations are not tracked. Additionally, the moocfi_cses.py file has been refined by replacing logging.debug calls with logger.debug, enhancing logging consistency and clarity during the login process and cookie file reading.

Changes

File Change Summary
.gitignore Added .envrc to the list of ignored files.
.../moocfi_cses.py Replaced logging.debug with logger.debug for improved logging during login and cookie handling.

In code we trust, with logs so clear,
Debugging woes shall disappear.
Ignore the noise, .envrc be gone,
Our repository stays lean and strong.
🎩🐰✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@senior-dev-bot senior-dev-bot bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feedback from Senior Dev Bot

Comment on lines 6 to +9
*.json
cookies.txt
.coverage
.envrc

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

It appears you've added .envrc which is useful for environment variable management but this type of file should not be part of the version control to avoid accidentally exposing sensitive information. Consider adding .envrc to your .gitignore to prevent it from being tracked. Here's how you can do it:

echo '.envrc' >> .gitignore

Comment on lines 64 to 70
action = login_form.get("_action")
login_form.pop("_action")
else:
logging.debug(
logger.debug(
f"url: {res.url}, status: {res.status_code}\nhtml:\n{res.text}"
)
raise ValueError("Failed to find login form")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

The change from logging.debug to logger.debug suggests you've switched from using the module-level logging to an instance of a logger. It's crucial to ensure logger is properly configured to handle messages at the debug level. Also, consider sanitizing sensitive information from res.text before logging, for security reasons.

Example:

# Ensure `logger` is set up correctly
logger.setLevel(logging.DEBUG)

# When logging responses, avoid logging sensitive information
logger.debug(f"url: {res.url}, status: {res.status_code}")

Comment on lines 79 to 85
)

if not self.is_logged_in:
logging.debug(
logger.debug(
f"url: {res.url}, status: {res.status_code}\nhtml:\n{res.text}"
)
raise ValueError("Login failed")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

Good job updating from logging to a more instance-specific logger object which likely offers better control and configuration suited to this context. However, ensure logger is properly defined and configured in this class or module. It might also be prudent to censor or limit the amount of sensitive information (like full HTML content) logged, as it can potentially include sensitive data, impacting both performance and security.

if not self.is_logged_in:
    logger.debug(f"url: {res.url}, status: {res.status_code}")
    raise ValueError("Login failed")

Comment on lines 194 to 200
with open(cookiefile, "r") as f:
return json.load(f)
except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
logging.debug(f"Error reading cookies from {cookiefile}: {e}")
logger.debug(f"Error reading cookies from {cookiefile}: {e}")
return {}


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

The update from logging to logger suggests a move to a more modular or instance-specific logging, which is a good practice for manageability and granularity in larger applications. Just ensure that the logger object is properly configured elsewhere in your code to handle debug-level messages. Additionally, consider enhancing error handling by not just logging but also informing the calling function or user in a way that does not disrupt the user experience or system stability. For example:

try:
    with open(cookiefile, "r") as f:
        return json.load(f)
except (FileNotFoundError, json.decoder.JSONDecodeError) as e:
    logger.debug(f"Error reading cookies from {cookiefile}: {e}")
    # Potentially consider a more user-friendly error strategy here
return {}

Comment on lines 53 to 59
if login_link:
login_url = urljoin(res.url, login_link.get("href"))
else:
logging.debug(
logger.debug(
f"url: {res.url}, status: {res.status_code}\nhtml:\n{res.text}"
)
raise ValueError("Failed to find login url")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW

The change from logging.debug to logger.debug suggests a move from the module-level logging to an instance (or named) logger, which is generally good for more granular control over logging. However, ensure that logger is properly set up earlier in the code. Also, consider whether including the entire response text (res.text) in the logging is always safe and necessary, as it can be too verbose or include sensitive information. If the response text is essential for debugging, ensure it's handled securely.

if login_link:
    login_url = urljoin(res.url, login_link.get("href"))
else:
    logger.debug(f"url: {res.url}, status: {res.status_code}")  # Consider logging `res.text` conditionally or securely.
    raise ValueError("Failed to find login url")

Copy link

============================= test session starts ==============================
platform linux -- Python 3.10.14, pytest-8.2.0, pluggy-1.5.0
rootdir: /home/runner/work/moocfi_cses/moocfi_cses
plugins: requests-mock-1.12.1, cov-5.0.0
collected 11 items

tests/test_moocfi_cses.py ...........                                    [100%]

---------- coverage: platform linux, python 3.10.14-final-0 ----------
Name                        Stmts   Miss  Cover
-----------------------------------------------
moocfi_cses.py                219    118    46%
tests/__init__.py               0      0   100%
tests/test_moocfi_cses.py      48      0   100%
-----------------------------------------------
TOTAL                         267    118    56%


============================== 11 passed in 0.10s ==============================

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 63f2c3d and a6f6c18.
Files selected for processing (2)
  • .gitignore (1 hunks)
  • moocfi_cses.py (4 hunks)
Files skipped from review due to trivial changes (1)
  • .gitignore
Additional comments not posted (3)
moocfi_cses.py (3)

56-58: Use of logger.debug instead of logging.debug is correct and ensures the use of the custom logger.


67-69: Use of logger.debug instead of logging.debug is correct and ensures the use of the custom logger.


197-197: Use of logger.debug instead of logging.debug is correct and ensures the use of the custom logger.

@madeddie madeddie merged commit c532e7c into main May 14, 2024
1 check passed
@madeddie madeddie deleted the fix_logging branch May 14, 2024 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant